<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = []
    while (arr.length < 5) {
      let age = +prompt(`请输入第${arr.length + 1}个人的年龄`)
      age >= 0 && age <= 300 && arr.push(age)
    }
    alert(`五个人的年龄分别是：${arr}`)

    let arr1 = []
    let sum = 0
    let avg = 0
    for (let i = 0; i < arr.length; i++) {
      if (arr[i] >= 18) {
        arr1.push(arr[i])
      }
      sum += arr[i]
    }

    arr.sort((a, b) => a - b)
    console.log(arr);
    console.log(`成年人年龄为：${arr1}`);
    console.log(`年龄总和为：${sum}`);
    console.log(`平均年龄为：${parseInt(sum / arr.length)}`);
    console.log(`年龄最大的是${arr[arr.length - 1]}`);
    console.log(`年龄最小的是${arr[0]}`);

  </script>
</body>

</html>